
<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>


<div class="panel ">
	<div class="panel-body pan" style="height: 430px">
			<div class="form-body pal">
				<div class="row" style="margin-top:-15px; margin-bottom: 10px;">
					<div class="col-lg-6" style="width: 100%; float:left;">
						<label for="inputUsername" class="col-md-3 control-label">数据库中文名
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="nameZh" type="text" class="form-control" value="" />
							</div>
						</div>
					</div>
					<div class="col-lg-6" style="width: 100%; float:left; ">
						<label for="inputUsername" class="col-md-3 control-label">数据库英文名
							<span class='require' id="mima">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="nameEn" type="text" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">连接类型
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="dbType" class="form-control">
									<option value="mysql">mysql</option>
								</select>
							</div>
						</div>
					</div>
					<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">URL地址
							<span class='require' >*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="dbUrl" type="text" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="row" style="margin-bottom: 10px;">
					<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">用户名
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="dbUser" type="text" class="form-control" value="" />
							</div>
						</div>
					</div>
					<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">密码
							<span class='require' id="yonghu">*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="dbPassword" type="password" class="form-control" value="" />
							</div>
						</div>
					</div>
					<div class="col-lg-6" style="width: 100%; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label">状态
							<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<select id="status" class="form-control">
									<option value="0">启用</option>
									<option value="1">禁用</option>
								</select>
							</div>
						</div>
					</div>
				</div> 	
				<input id="id" type="hidden" class="form-control" />
	</div>
</div>
<?} ?>
<script>
function getQueryString(name) { 
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r != null) return unescape(r[2]); return null; 
	} 
var winName=getQueryString("winName");

	var saveUploadDatabaseId = window.parent.window[winName].getSaveUploadDatabaseId();
	$(function() {
		$("#id").val(saveUploadDatabaseId);
		if('0' != saveUploadDatabaseId){
			demo();
		}
	});
	
	function Page() {
		if ($.trim($("#nameZh").val()).length < 1) {
			alert('数据库中文名不能为空！');
			return null;
		}
		if ($.trim($("#nameEn").val()).length < 1) {
			alert('数据库英文名不能为空！');
			return null;
		}
		if ($.trim($("#dbUrl").val()).length < 1) {
			alert('URL地址不能为空！');
			return null;
		}
		if ($.trim($("#dbUser").val()).length < 1) {
			alert('用户名不能为空！');
			return null;
		}
		if ($.trim($("#dbPassword").val()).length < 1) {
			alert('密码不能为空！');
			return null;
		}
		$.ajax({
			type : "post",
			url : "saveEditDatabase.do",
			data : {
				"id" : $("#id").val(),
				"nameZh" : $("#nameZh").val(),
				"nameEn" : $("#nameEn").val(),
				"dbType" : $("#dbType").val(),
				"dbUrl" : $("#dbUrl").val(),
				"dbUser" : $("#dbUser").val(),
				"dbPassword" : $("#dbPassword").val(),
				"status" : $("#status").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name); 
				window.parent.window[winName].demo();
				if(data[0] == 'yes'){
					window.parent.window[winName].layer.msg('提交成功');
				}else{
					window.parent.window[winName].layer.msg('提交失败');
				}
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	function demo() {
		$.ajax({
			type : "post",
			url : "findDatabase.do",
			data : {
				"id" : saveUploadDatabaseId,
			},
			dataType : "json",
			async : false,
			success : function(data) {
				$("#id").val(data[0].id);
				$("#nameZh").val(data[0].nameZh);
				$("#nameEn").val(data[0].nameEn);
				$("#dbType").val(data[0].dbType);
				$("#dbUrl").val(data[0].dbUrl);
				$("#dbUser").val(data[0].dbUser);
				$("#dbPassword").val(data[0].dbPassword);
				$("#status").val(data[0].status);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	};

</script>


